var app = getApp();
Page({
  data:{
     cateList:[],

      subjectList:[
        {
          type:'单选题',
          totalCount:160,
          topScore:0,
          url:'/rs_anwser/pages/single_subject/single_subject',
          examUrl:'/rs_anwser/pages/single_exam/single_exam',
          collectUrl:'/rs_anwser/pages/single_collect/single_collect',
          wrongUrl: "/rs_anwser/pages/single_wrong_list/single_wrong_list"
        },
        {
          type: '多选题',
          totalCount: 160,
          topScore: 0,
          url: '/rs_anwser/pages/mutilple_subject/mutilple',
          examUrl: '/rs_anwser/pages/mutilple_exam/mutilple',
          collectUrl: '/rs_anwser/pages/mutilple_collect/mutilple_collect',
          wrongUrl: '/rs_anwser/pages/mutilple_wrong_list/mutilple_wrong_list'
        },
        {
          type: '判断题',
          topScore: 0,
          url: '/rs_anwser/pages/judge_subject/judge',
          examUrl: '/rs_anwser/pages/judge_exam/judge_exam',
          collectUrl: '/rs_anwser/pages/judge_collect/judge_collect',
          wrongUrl:'/rs_anwser/pages/judge_wrong_list/judge_wrong_list'
        },
        {
          type: '问答题',
          totalCount: 160,
          topScore: 0,
          url: '/rs_anwser/pages/question_subject/question_subject',
          examUrl: '/rs_anwser/pages/com_exam/com_exam',
          collectUrl: '/rs_anwser/pages/question_collect/question_collect'
        }
      ],
     currentActiveNav:0
  },
  navClick:function(event){
    var cateList = this.data.cateList;
    var last =  this.data.currentActiveNav;
     var current = event.currentTarget.dataset.index;
    cateList[last].active_class = '';
    cateList[current].active_class='nav-active';
    this.setData({cateList:cateList,currentActiveNav:current});
    


  },
  toExercise:function(e){
    var index = e.currentTarget.dataset.index;
    wx.navigateTo({
      url:this.data.subjectList[index].url
     })
  },
  showCollect:function(e){
    var index = e.currentTarget.dataset.index;
    wx.navigateTo({
      url: this.data.subjectList[index].collectUrl
    })
  },
  toExam:function(e){
     var url=e.currentTarget.dataset.url;
     wx.navigateTo({
       url: url,
     })
  },
  showWrongSubject:function(e){
    var index = e.currentTarget.dataset.index;
  
    wx.navigateTo({
      url: this.data.subjectList[index].wrongUrl
    })
  },
  showScore:function(e){
    var index = e.currentTarget.dataset.index;
   
    var subjectType = '';
    if(index==0){
        subjectType = 'single';   
    }else if(index == 1){
        subjectType = 'mutilple';
    }else if(index == 2){
      subjectType = 'judge';
    }else if(index == 3){
      subjectType = 'com';
    }

    wx.navigateTo({
      url: '/rs_anwser/pages/score/score?subjectType='+subjectType
    })
  },
  onLoad:function(options){
    var userInfo = wx.getStorageSync('userInfo');
    if (userInfo == false) {
      wx.navigateTo({
        url: '/rs_anwser/pages/start/start',
      })
    }

    // 页面初始化 options为页面跳转所带来的参数
    var me  = this;
    var userInfo = wx.getStorageSync('userInfo');
   
    app.util.request({
      url:'entry/wxapp/index',
      data:{
        m:'rs_anwser',
        openId:userInfo.openId
      },
      method:'post',
      success:function(data){
         var indexData = data.data.data;
         var cateList = indexData.cateList;
         cateList[0]['active_class'] = 'nav-active';
         var subjectList = me.data.subjectList;
         subjectList[0]['totalCount'] = indexData.singleCount;
         subjectList[0]['topScore'] = indexData.scores.topSingleScore;
         subjectList[1]['totalCount'] = indexData.mutilpleCount;
         subjectList[1]['topScore'] = indexData.scores.topMutilpleScore;
         subjectList[2]['totalCount'] = indexData.judgeCount;
         subjectList[2]['topScore'] = indexData.scores.topJudgeScore;
         me.setData({ cateList: cateList, subjectList: subjectList});
      }
    })
    
  },
  onReady:function(){
   
  },
  onShow:function(){
   
     
  },
  onHide:function(){
    // 页面隐藏
  },
  onUnload:function(){
    // 页面关闭
  },
  onShareAppMessage(object){

    console.log(object);

  }

})